const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    cocos: cc.Node = null;
    sprite: cc.Sprite = null;
    mat: cc.Material = null;

    _glowSize: number = 0.0;
    get glowSize() {
        return this._glowSize;
    }
    set glowSize(v) {
        this._glowSize = v;
        this.updateMaterial();
    }

    onLoad() {
        this.sprite = this.cocos.getComponent(cc.Sprite);
        this.mat = this.sprite.getMaterial(0);
        cc.tween(this)
            .repeatForever(
                cc.tween()
                    .to(2, { glowSize: 2.0 })
                    .to(2, { glowSize: 0.0 })
            )
            .start();
    }

    updateMaterial() {
        if (this.mat) {
            this.mat.setProperty('glowSize', this._glowSize);
            this.sprite.setMaterial(0, this.mat);
        }
    }
}
